<template>
  <div class="card" :id="id">
    <input type="radio" :checked="state">
    <img :src="img" class="img">
    <div class="card-right">
      <div class="fruit">{{fruitName}}</div>
      <div class="btn">
        <button @click="jian">-</button>
        <p class="count">{{fruitCount}}</p>
        <button @click="add">+</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MyCard',
  props: ['fruitName', 'fruitCount', 'img', 'id', 'state'],
  emits: ['update:fruitCount'],
  data() {
    return {};
  },
  methods: {
    jian() {
      if (this.fruitCount > 0) {
        this.$emit('update:fruitCount', this.fruitCount - 1);
      }
    },
    add() {
      this.$emit('update:fruitCount', this.fruitCount + 1);
    }
  }
};
</script>

<style scoped>
.card {
  height: 100px;
  line-height: 100px;
  display: flex;
  border-bottom: 1px solid rgb(182, 182, 182);
}
.img {
  flex: 1;
  width: 100px;
  height: 100px;
  border-radius: 50%;
}
.card-right {
  width: 20%;
  text-align: center;
}
.fruit {
  height: 60px;
  line-height: 60px;
}
.btn {
  height: 20px;
  line-height: 20px;
  display: flex;
}
.count {
  margin: 0 5px;
}
</style>